<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加参赛项目</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input id="id" name="id" type="text" hidden="hidden" />
    <div class="layui-form-item">
        <label class="layui-form-label required">参赛项目</label>
        <div class="layui-input-block">
            <input type="text" id="projectname" name="projectName" lay-verify="required" lay-reqtext="项目名不能为空" placeholder="请输入项目名" value="" class="layui-input">
            <!--<tip>填写自己管理账号的名称。</tip>-->
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">项目介绍</label>
        <div class="layui-input-block">
            <!--<input type="textarea" id="projecttro" name="projectTro" lay-verify="required" lay-reqtext="介绍不能为空" placeholder="请输入介绍" value="" class="layui-input">-->
            <textarea type="textarea" id="projecttro" name="projectTro" lay-verify="required" lay-reqtext="介绍不能为空" placeholder="请输入介绍" value="" class="layui-input"></textarea>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">成绩/单位</label>
        <div class="layui-input-block">
            <input type="text" id="unit" name="unit" lay-verify="required" lay-reqtext="成绩不能为空" placeholder="请输入成绩" value="" class="layui-input">

        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block" id="genderLimit">
            <input type="radio" name="genderLimit" value="0" title="男">
            <input type="radio" name="genderLimit" value="1" title="女" checked="">


        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">参赛场所</label>
        <div class="layui-input-block">
            <input type="text" id="place" name="place" placeholder="请输入参赛场所" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">报名人数</label>
        <div class="layui-input-block">
            <input type="text" id="takenum" name="takeNum"  value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">比赛日期</label>
            <div class="layui-input-block">
                <input type="text" name="date" id="date1" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-inline">-->
        <!--<label class="layui-form-label">比赛日期</label>-->
        <!--<div class="layui-input-inline">-->
        <!--<input type="text" class="layui-input" id="test1" placeholder="yyyy-MM-dd HH:mm:ss">-->
        <!--</div>-->
        <!--</div>-->
        <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="test2" name="startTime" placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束日期</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="test3" name="endTime" placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">参加状态</label>
            <div class="layui-input-inline">
                <input type="checkbox" lay-verify="required" lay-filter="status" id="status" name="deleted" lay-skin="switch" lay-text="已参加|待参加">
            </div>
        </div>

    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <!--<a  href="project-select.html" class="layui-btn" target="_blank" data-icon="fa fa-gears" lay-event="edit">查看参赛选手</a>-->
            <!--<a  href="javascript:document.getElementById('layui-layer-iframe1').src='http://www.sohu.com' " onclick="document.getElementById('layui-layer-iframe1').src='http://www.sohu.com' " class="layui-btn" target="_blank" data-icon="fa fa-gears" lay-event="edit">查看参赛选手</a>-->

            <!--<button onclick="tast();"  class="layui-btn layui-btn-xs data-count-edit"  lay-event="edit">查看参赛选手</button>-->
            <button onclick="tast();"  class="layui-btn"  lay-event="edit">查看参赛选手</button>
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>



<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/utils.js"></script>
<script>
    function tast(){
        // var frame1=document.getElementById('layui-layer-iframe1');
        // var id=document.getElementById("id");
        var $ = layui.$;
        var  index= layer.open({
            type: 2,
            title: '查看参赛选手',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['100%', '100%'],
            content: 'project-select.html?pid='+$("#id").val()
        });
        // $(window).on("resize", function () {
        //     layer.full(index);
        // });
    }
    layui.use(['form','laydate','table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            laydate = layui.laydate,//日期
            $ = layui.$;
        //监听性别操作
        // form.on('switch(sexDemo)', function(obj){
        //     layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
        // });


//日期时间选择器
        laydate.render({
            elem: '#date1'

        });

//         laydate.render({
//             elem: '#test1'
//
//             ,type: 'datetime'
//         });
        laydate.render({
            elem: '#test2'

            ,type: 'datetime'
        });
        laydate.render({
            elem: '#test3'

            ,type: 'datetime'
        });

    console.log(GetQueryString_new("id"))

        $.ajax({

            type:"GET",
            url:"/sport/project/findId",
            data:{
                id:GetQueryString_new("id")
            },

            async:false,
            success:function (data) {
                console.log(data)
                $('#id').val(data.id);
                $('#projectname').val(data.projectName);
                $('#projecttro').val(data.projectTro);
                $('#unit').val(data.unit);
                $('#genderLimit').val(data.genderLimit);
                // $('#sex input[name="genderLimit"]').val(data.genderLimit);
                if (data.genderLimit==1){
                    $('input[name="genderLimit"]').attr("checked", true);
                    layui.form.render();//渲染页面
                }

                // $.trim($("#sex").val(data.genderLimit));

                $('#place').val(data.place);

                $('#date1').val(data.date);
                $('#test2').val(data.startTime);
                $('#test3').val(data.endTime);
                $('#takenum').val(data.takeNum);
                // $('#deleted').val(data.deleted);
                console.log(data.deleted);
                if (data.deleted==1){
                    $("input[name=deleted]").attr("checked", true);
                    layui.form.render();//渲染页面
                }
            }
        });
        //查看项目列表
        // table.on('tool(currentTableFilter)', function (obj) {
        //     // $('#edit').on('click',function (obj) {
        //     var data = obj.data;
        //     if (obj.event === 'edit') {
        //
        //         var index = layer.open({
        //             // title: '编辑参赛项目',
        //             title: '查看参赛项目',
        //             type: 2,
        //             shade: 0.2,
        //             maxmin:true,
        //             shadeClose: true,
        //             area: ['100%', '100%'],
        //             content: 'project-select.html',
        //         });
        //         $(window).on("resize", function () {
        //             layer.full(index);
        //         });
        //         // return false;
        //     }
        // });
        var static1;
        // //开关
        form.on('switch(status)',function (data) {
            //开关是否开启，true或者false
            static1 = data.elem.checked;
        });
        //保存监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field),
                {
                title: '最终的提交信息'
            },
                function () {
                var static2;
                if ( static1==true){
                    static2=1;
                }else{
                    static2=0;
                }
                // 关闭弹出层
                layer.close(index);
                //修改信息
                $.ajax({
                    type:"GET",
                    url:"/sport/project/update",
                    // data:data.field,
                    data:{
                        id:$('#id').val(),
                        projectName:  $('#projectname').val(),
                        projectTro: $('#projecttro').val(),
                        unit: $('#unit').val(),
                        genderLimit: $('.gender').val(),
                // $('#sex input[name="genderLimit"]').val(data.genderLimit);
                // $.trim($("#sex").val(data.genderLimit));

                         place:  $('#place').val(),

                        date: $('#date1').val(),
                        startTime:$('#test2').val(),
                        endTime:$('#test3').val(),
                        takeNum: $('#takenum').val(),
                         deleted:static2
                    },
                    error:function () {

                        alert("修改失败");
                    },
                    success:function (data) {
                        console.log(data)
                        if (data.code == 0){
                            layer.alert(data.msg,{icon: 6},function () {
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                window.parent.location.reload();//成功后刷新父界面
                            });

                        } else{
                            layer.alert(data.msg, {icon: 6});
                        }

                    }
                });

            });

            return false;
        });

    });
</script>
</body>
</html>